package baseClass;

import DataProcess.ServicePage;
import baseAPI.Database;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import java.sql.ResultSet;
import java.sql.SQLException;

public class ServiceTable {
    public static final int WAKE_UP = 1;
    public static final int CLEAN = 2;
    public static final int MEAL = 3;

    private SimpleStringProperty roomNumber = new SimpleStringProperty();
    private SimpleStringProperty service = new SimpleStringProperty();
    private SimpleStringProperty note = new SimpleStringProperty();
    private int serviceType;

    public ServiceTable(int roomNumber, int service, String note){
        this.roomNumber.set(String.valueOf(roomNumber));

        serviceType = service;
        switch (service){
            case 1: this.service.set("早晨叫醒");break;
            case 2: this.service.set("保洁服务");break;
            case 3: this.service.set("点餐服务");break;
        }

        this.note.set(note);
    }

    public String getRoomNumber(){
        return roomNumber.get();
    }

    public String getService(){
        return service.get();
    }

    public String getNote(){
        return note.get();
    }

    public static ObservableList<ServiceTable> getServiceTable(Database database, int service){
        ObservableList<ServiceTable> services = FXCollections.observableArrayList();
        ResultSet resultSet = database.select("*", "service", "service = " + service);
        try {
            if(!resultSet.next()){
                return null;
            }
            else{
                do{
                    services.add(new ServiceTable(resultSet.getInt(1), resultSet.getInt(2), resultSet.getString(3)));
                }while(resultSet.next());
                return services;
            }
        }catch (SQLException ex){
            System.out.println("getServiceTableException");
        }
        return null;
    }

    public void setHandled(Database database){//已经被解决
        database.delete("service", "roomNumber = " + roomNumber.get() + " and service = " + serviceType + " and note = " + "\"" + note.get() + "\"");
    }
}
